﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ClientAppViaWebService.DepartmentsLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class DepartmentEditForm : EducationalDivisionEditForm
    {
        DepartmentsLogicService lService;
        private readonly Int32 ClassID = 6;

        public DepartmentEditForm()
        {
            InitializeComponent();
            lService = new DepartmentsLogicService();
            classTextBox.Text = ClassID.ToString();
        }

        public String Specialization
        {
            get { return specializationTextBox.Text; }
            set { specializationTextBox.Text = value; }
        }

        public Int32 MaxPostgraduates
        {
            get { return Int32.Parse(maxPostgraduatesTextBox.Text); }
            set { maxPostgraduatesTextBox.Text = value.ToString(); }
        }

        protected override void SetFormProperties(Object _object)
        {
            Department d = (_object as Department);
            ID = d.ID;
            EXT_ID = d.EXT_ID;
            ParentId = d.PARENT_ID;
            Class = d.CLASS_ID;
            ObjName = d.NAME;
            BossName = d.BOSS_ID;
            DateCreated = d.DATE_CREATED;
            Description = d.DESCRIPTION;
            Specialization = d.SPECIALIZATION;
            MaxPostgraduates = d.MAX_POSTGRADUATES;
        }

        protected override Object RetrieveFormProperties()
        {
            Department dep = new Department();
            dep.ID = ID;
            dep.EXT_ID = EXT_ID;
            dep.PARENT_ID = ParentId;
            dep.CLASS_ID = Class;
            dep.NAME = ObjName;
            dep.DataBaseName = DataBaseName;
            dep.BOSS_ID = BossName;
            dep.DATE_CREATED = DateCreated;
            dep.DESCRIPTION = Description;
            dep.SPECIALIZATION = Specialization;
            dep.MAX_POSTGRADUATES = MaxPostgraduates;
            return dep;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            Department p = lService.SelectDepartment_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            Department obj = RetrieveFormProperties() as Department;
            lService.UpdateDepartment(obj);
        }

        protected override void InsertEntity()
        {
            Department obj = RetrieveFormProperties() as Department;
            lService.InsertDepartment(obj);
        }
    }
}
